package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.eunm.ActivityEnums;
import com.ytjj.qmyx.admin.model.response.ActivityTypeResponse;
import com.ytjj.qmyx.admin.service.ActivityColumnService;
import com.ytjj.qmyx.mall.model.ActivityColumn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *
 *
 * @Version: 1.0
 * <p>
 * 活动栏目 模块
 */
@RestController
@RequestMapping("/activityColumn")
public class ActivityColumnController {

    @Autowired
    private ActivityColumnService activityColumnService;

    @GetMapping("/getTitle")
    public CommonResult getTitle(@RequestParam("type") String type) {
        return CommonResult.success(activityColumnService.getTitleByTitle(type));
    }

    @PostMapping("/getType")
    public CommonResult getType() {
        return CommonResult.success(activityColumnService.getType());
    }

    /**
     * 获取活动类型
     */
    @GetMapping("/getActivityType")
    public CommonResult getActivityType() {
        Map<String, String> eumValueList = ActivityEnums.getEumValueList();
        Set<Map.Entry<String, String>> entries = eumValueList.entrySet();
        List<ActivityTypeResponse> list = new ArrayList<>();
        for (Map.Entry<String, String> entry : entries) {
            ActivityTypeResponse activityTypeResponse = new ActivityTypeResponse();
            activityTypeResponse.setCode(entry.getKey());
            activityTypeResponse.setName(entry.getValue());
            list.add(activityTypeResponse);
        }
        return CommonResult.success(list);
    }

    /**
     * 查询活动栏目列表
     * @param type 活动类型
     * @param title 栏目名称
     * @param isShow 是否显示
     * @param pageNum 页数
     * @param pageSize 页码
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam(required = false) String type,
                             @RequestParam(required = false) Integer id,
                             @RequestParam(required = false) String title,
                             @RequestParam(required = false) Integer isShow,
                             @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                             @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return activityColumnService.list(id, type, title, isShow, pageNum, pageSize);
    }

    /**
     * 新增或编辑活动栏目
     */
    @PostMapping("/editColumn")
    public CommonResult editColumn(@RequestBody ActivityColumn activityColumn){
        return activityColumnService.editColumn(activityColumn);
    }
}
